<?php
namespace Admin\Controller;

class MenuController extends AdminController {
    //菜单列表
    public function index(){
        $data = D('Data') -> getMenu(10);
        $menu = $data['menu'];
        $page = $data['page'];
        $this->assign('menu',$menu);
        $this->assign('_page',$page);
        $this->display();
    }

    //菜单删除
    public function del($id){
        if(M('Menu')->delete(intval(I('get.id')))){
            $this->success('删除成功');
        } else {
            $this->error('删除失败！');
        }
    }
    
    
    //菜单添加
    public function add(){
        if(IS_POST){
            $data = array('menu_name'=>I('post.menu_name'),'linkurl'=>I('post.linkurl'),'hide'=>intval(I('post.hide')),'pid'=>intval(I('post.pid')));
            if(M('Menu')->add($data)){
                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }
        }else{
            $menu = D('Data')->getLevelMenu();
            $this->assign('menu',$menu);
            $this->display();
        }
    }

    /*菜单编辑*/
    public function edit(){
        if(IS_POST){
            $data = array('menu_name'=>I('post.menu_name'),'linkurl'=>I('post.linkurl'),'hide'=>intval(I('post.hide')),'pid'=>intval(I('post.pid')),'id'=>intval(I('post.id')));
            $res = M('Menu') -> save($data);
            $res?$this->success('编辑成功'):$this->error('编辑失败');
        }else{
            $Level = D('Data')->getLevelMenu();
            $menu = M('Menu')->find(intval(I('get.id')));
            $this->assign('menu',$menu);
            $this->assign('Level',$Level);
            $this->display();
        }
    }



}